package com.app.logcat;

import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import com.zndroid.logcat.Config;
import com.zndroid.logcat.LogcatX;
import com.zndroid.logcat.displayer.LogLevel;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                Log.w("fff", "opopopopopo");
            }
        }, 0 ,1000);

        if (!Settings.canDrawOverlays(this)) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
            intent.setData(Uri.parse("package:" + getPackageName()));
            startActivityForResult(intent, 123);
        }

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 456);
    }

    public void start(View view) {
        Config config = new Config();
//        config.setLogcatColors(LogLevel.WARNING, android.R.color.holo_blue_bright);
//        config.setLogSavePath(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getPath());
        LogcatX.getInstance().setConfig(config);
        LogcatX.getInstance().display(getApplication());
    }

    public void stop(View view) {
        LogcatX.getInstance().close();
    }

    public void jump(View view) {
        startActivity(new Intent(this, SecondActivity.class));
    }
}